<?php
require_once('lib/member.php');
require_once('lib/utils.php');

// admin/modo
$is_admin = $_SESSION['status_code'] == 'ADMIN';

$members = member_get_by_status('MEMBER');
$count = mysql_num_rows($members);
?>
<script src="pages_admin/adherents/adherents.js" type="text/javascript"></script>
<div id="adherents">
	<h3>Liste des adhérents</h3>

	<?php
	if ($row = mysql_fetch_assoc($members)) {
		echo '<span class="table"><strong id="nbmember">'.$count.'</strong> '.plural('adhérent', $count).' '.plural('inscrit', $count).'</span>';
		?>
		<table class="dataTable">
			<thead>
			<tr>
				<th>Nom</th>
				<th>Prénom</th>
				<th>Date naissance</th>
				<th>Date d'inscription</th>
				<th>Gymnase</th>
				<th>Action</th>
			</tr>
			</thead>
			<tbody>
			<?php
			do {
				echo '
				<tr id="ligne'.$row['id'].'">
					<td>'.$row['name'].'</td>
					<td>'.$row['firstname'].'</td>
					<td>'.$row['birth'].'</td>
					<td>'.date_to_str($row['date_registration']).'</td>
					<td>'.$row['gym_name'].'</td>
					<td class="action">
						<a href="javascript:details('.$row['id'].');" title="Voir les détails">
							'.icon_tag('magnifier').'
						</a>';

						if ($is_admin)
							echo '
							<a href="index.php?p=inscription&id='.$row['id'].'" title="Modifier les informations">
								'.icon_tag('pencil').'
							</a>

							<span>
								<a href="javascript:void(0);" class="js-ask-validation" title="Annuler et repasser en liste d\'attente">
									'.icon_tag('arrow_undo').'
								</a>
								<span class="hidden confirm-box">
									Passer en liste d\'attente ?<br />
									<a href="javascript:void(0);" class="js-cancel-registration b-oui" id="cancelmember_'.$row['id'].'"></a>
									<a href="javascript:void(0);" class="js-hide b-non"></a>
								</span>
							</span>
							<span>
								<a href="javascript:void(0);" class="js-ask-validation" title="Supprimer cet adhérent">
									'.icon_tag('delete').'
								</a>
								<span class="hidden confirm-box">
									Supprimer définitivement ?<br />
									<a href="javascript:void(0);" class="js-delete-member b-oui" id="deletemember_'.$row['id'].'"></a>
									<a href="javascript:void(0);" class="js-hide b-non"></a>
								</span>
							</span>';
						echo '
					</td>
				</tr>';
			} while ($row = mysql_fetch_assoc($members));
			?>
			</tbody>
		</table>
		<?php
	}
	else {
		if (isset($recherche) && $recherche) {
			?>
			<p class="warning">Aucune demande ne correspond à votre recherche</p>
			<?php
		}
		else {
			?>
			<p class="info">Il n'y a pas encore d'inscription validée</p>
			<?php
		}
	}
	?>
</div>
